<template>
	<mescroll-uni :ref="'mescrollRef'+tabIndex" @init="mescrollInit" @down="downCallback" @up="upCallback">
		<view class="u-padding-left-32 u-padding-right-32 swiper-box-padding" v-if="dataList.length">
			<view v-for="(item,index) in dataList" :key="index" class="u-margin-top-20" @click="goPathDetail(item)">
				<list-item :item="item" :showStar="false" :showFooterRight="false" :isShare="false" height="292"
					:showTop="tab.name=='未测'&&!!uid" @setTop="setTop" showType>
					<view slot="content" class="text-order-666 u-font-26">
						<view class="desc u-font-24 content-desc-item u-line-3">
							展会酒店地址：{{item.hotelAddress || ''}}{{item.hotelRoomNo || ''}}
						</view>
						<view class="u-flex u-margin-top-6">
							<flex-text txt="开放上车时间" size="24" width="145"></flex-text>
							<text class="u-font-26">：{{item.enrollTime | timeFormat}}</text>
						</view>
						<view class="u-flex u-margin-top-10">
							<flex-text txt="发车时间" size="24" width="145"></flex-text>
							<text class="u-font-26">：{{item.estimateTime | timeFormat}}</text>
						</view>
					</view>
					<view slot="footer-end" class="u-flex u-row-left u-margin-top-15 u-row-between">
						<template v-if="tab.name!=='已测'">
							<view class="u-font-30 u-flex-1 u-text-right">
								<text class="text-color-txtTheme">{{item.participate}}</text>/{{item.people}}人
							</view>
							<view class="u-flex-1 u-padding-left-30">
								<item-btn
									:bgColor="item.participate==item.people ? currentThemeObj.btnDisableBgcolor : currentThemeObj.primary"
									v-if="isStore&&!item.isIntoCar" :disabled="item.participate==item.people"
									@click="pushCar('confirmCar',item)" width="190" height="64"
									:loading="intoCarLoading">一键上车</item-btn>

								<item-btn v-if="isStore&&item.isIntoCar" width="190" height="64"
									@click="closeCar('storeCancelCar',item)" :loading="outCarLoading">我要下车</item-btn>

								<item-btn v-if="!isStore" width="190" height="64" @click="closeCar('cancelCar',item)"
									:loading="outCarLoading">取消发车</item-btn>
							</view>
						</template>
						<template v-if="isStore&&tab.name==='已测'">
							<view>
								<item-btn
									:bgColor="item.isEvaluation ? currentThemeObj.btnDisableBgcolor : currentThemeObj.primary"
									@click="reply(item)" width="190" height="64">{{!item.isEvaluation?'待评测':'已评测'}}
								</item-btn>
							</view>
							<view>
								<item-btn
									:bgColor="item.isSubmitIntention ? currentThemeObj.btnDisableBgcolor : currentThemeObj.primary"
									@click="want(item)" width="190" height="64">{{!item.isSubmitIntention?'提意向':'已提交'}}
								</item-btn>
							</view>
						</template>
						<!-- <item-btn @click="userList(item)" width="190" v-else height="64">参与店家信息</item-btn> -->
					</view>
				</list-item>
			</view>

		</view>
		<model v-model="modelFlag" :show-title="false" :show-cancel-button="modelType!=='rejectFlag'"
			:show-confirm-button="modelType!='confirmCar'"  cancel-color="#333333" :confirm-color="currentThemeObj.primary"
			:content="closeModalTips" @confirm="confirmClose" @cancel="clearTime" />
	</mescroll-uni>
</template>

<script>
	import upCallback from '@/mixins/upCallbackMixin.js'
	import carManager from '@/mixins/carManager.js'
	import model from '@/components/u-modal/u-modal.vue'
	import {
		customRequest
	} from '@/api/crud.js'
	export default {
		mixins: [upCallback, carManager], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		props: {
			tab: {
				type: Object,
				default: () => ({})
			},
			tabIndex: {
				type: Number,
				default: 0
			},
			inputName: {
				type: String,
				default: ''
			},
			categoryIds: {
				type: Array,
				default: () => ([])
			}
		},
		components: {
			model
		},

		data() {
			return {
				apiType: "driveCar",
				apiModule: 'shopApi',
				name: 'thirdQuery',
				modelFlag: false,
				form: {},
				goon: {
					backgroundColor: '#765CFE',
					borderColor: 'none',
					width: '143rpx'
				},
				goonDis: {
					backgroundColor: 'rgba(118,92,254,0.4)',
					borderColor: 'none',
					width: '143rpx'
				},
			}
		},
		computed: {
			isStore() {
				return this.isAuth != 'issue'
			},
			isAuth() {
				const loginForm = this.loginForm;
				return loginForm && loginForm.userType || 'store'
			}
		},
		watch: {
			inputName(val) {
				this.$u.debounce(() => {
					this.form.name = val;
					this.downCallback();
				}, 300)
			}
		},
		created() {
			const {
				type,
				showEnrollTime
			} = this.tab;
			this.form = {
				type,
				status: type,
				showEnrollTime
			}
		},
		methods: {
			goPathDetail(item) {
				const url = this.isStore ? '/pagesA/goOnLarp/detail' : '/pagesA/goonLarpManager/detail'
				this.$u.route({
					url,
					params: {
						id: item.id
					}
				})
			},
			selectCallback(categoryIds, peopleDesc) {
				this.$set(this.form, 'categoryIds', categoryIds);
				this.$set(this.form, 'peopleDesc', peopleDesc);
				this.downCallback()
			},
			//评测
			reply(item) {
				if (item.isEvaluation) return false;
				this.$u.route({
					url: '/pagesA/userSubmit/userSubmit',
					params: {
						type: "settingTest",
						productId: item.productId,
						driveCarId: item.id
					}
				})
			},
			//意向
			want(item) {
				if (item.isSubmitIntention) return false;
				this.$u.route({
					url: '/pagesA/want/setting',
					params: {
						productId: item.productId,
						driveCarId: item.id,
            type:'drive_car' // 公车意向
					}
				})
			},
			cancelCarcallback(res) {
				this.dataList = this.dataList.filter(val => (val.id != res.id&&val.id != res.driveCarId));
				if (this.dataList.length === 0) {
					this.downCallback()
				}
			},
			//发车回调
			startCarcallback(res) {
				this.cancelCarcallback(res)
			},
			//上车回调
			intoCar(item) {
				this.sort()
				this.goPathDetail(item)
			},
			//排序
			sort() {
				this.dataList.sort(a => a.isIntoCar ? -1 : 1)
			},
			userList(item) {
				this.$u.route({
					url: '/pagesA/carUserList/carUserList',
					params: {
						id: item.id
					}
				})
			},
			//设置置顶
			setTop(data) {
				const isTop = data.isTop == 0
				customRequest({
					driveCardId: data.id,
					uid: this.uid,
					isTop
				}, 'driveCar', 'shopApi', 'isTopCar').then(res => {
					this.$u.toast(isTop ? '置顶成功' : '取消置顶成功')
					this.downCallback()
				})
			}
		}
	}
</script>

<style>
</style>
